import http from './urls'

const apiRequest = (url, method, data, header) => { //接收所需要的参数，如果不够还可以自己自定义参数
  return new Promise(function (resolve, reject) {
    wx.request({
      url: url,
      data: data ? data : null,
      method: method,
      header: header ? header : {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          resolve(res);
        } else {
          reject(res.data.msg)
        }
      },
      fail: function (err) {
        console.log(err, 'Promiss 666');
      }
    })
  });
}

// 首页
let home = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.home, 'POST', data))
  })
}

// 根据套餐id获取套餐详情
let PackageDetails = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.PackageDetails, 'POST', data))
  })
}

// 根据套餐分类名称获取套餐数据
let categoricalData = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.categoricalData, 'POST', data))
  })
}

// 一键救援获取门店列表
let storeList = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.storeList, 'POST', data))
  })
}

// 一键预约获取列表
let reservationList = (data) => {
  new Promise((resolve, reject) => {
    resolve(apiRequest(http.reservationList, 'POST', data))
  })
}

// 提交预约单
let submitReservationForm = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.submitReservationForm, 'POST', data))
  })
}

// 预约前获取门店及车主车辆数据
let vehicleData = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.vehicleData, 'POST', data))
  })
}

// 获取预约时间段列表
let timeList = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.timeList, 'POST', data))
  })
}

// 根据openid获取用户token
let getToken = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.getToken, 'POST', data))
  })
}

// 微信授权登录
let login = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.login, 'POST', data))
  })
}

// 根据车系id获取车型数据
let motorcycleTypeData = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.motorcycleTypeData, 'POST', data))
  })
}

// 根据车辆品牌id获取车系数据
let rangeData = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.rangeData, 'POST', data))
  })
}

// 获取车辆品牌列表
let vehicleBrandList = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.vehicleBrandList, 'POST', data))
  })
}

// 删除车辆
let deleteCar = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.deleteCar, 'POST', data))
  })
}

// 修改车辆
let amendCar = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.amendCar, 'POST', data))
  })
}

// 获取车辆详情
let carDetile = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.carDetile, 'POST', data))
  })
}

// 新增车辆
let newlyCar = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.newlyCar, 'POST', data))
  })
}

// 获取预约列表
let subscribeList = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.subscribeList, 'POST', data))
  })
}

// 获取车辆列表
let subscribeCarList = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.subscribeCarList, 'POST', data))
  })
}

// 上传行驶证
let uploadVehicle = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.uploadVehicle, 'POST', data))
  })
}

// 上传驾照
let uploadDrive = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.uploadDrive, 'POST', data))
  })
}

// 识别vin码获取vin及车辆品牌车系数据
let brandCarSystemData = (data) => {
  return new Promise((resolve, reject) => {
    resolve(apiRequest(http.brandCarSystemData, 'POST', data))
  })
}

export default {
  home,
  PackageDetails,
  categoricalData,
  storeList,
  reservationList,
  submitReservationForm,
  vehicleData,
  timeList,
  getToken,
  login,
  motorcycleTypeData,
  rangeData,
  vehicleBrandList,
  deleteCar,
  amendCar,
  carDetile,
  newlyCar,
  subscribeList,
  subscribeCarList,
  uploadVehicle,
  uploadDrive,
  brandCarSystemData
}
